﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using ETRoboConTrakingSystem;

namespace ETRobocon.RaceTraking.GamePresentation
{
    /// <summary>
    /// UserControlPresentationMain.xaml の相互作用ロジック
    /// </summary>
    public partial class UserControlPresentationMain : UserControl
    {
        public UserControlPresentationMain()
        {
            InitializeComponent();
            //       System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
            //       string imgPath = this.GetType().Namespace + ".imgs.";
            //       System.Diagnostics.Debug.WriteLine("Image Path:", imgPath);
            //       BitmapImage bi = new BitmapImage();
            //       bi.BeginInit();
            //            bi.UriSource = new Uri("imgs/courceIn.gif", UriKind.Relative);
            //       bi.StreamSource = myAssembly.GetManifestResourceStream(imgPath + "courceIn.jpg"); ;
            //       bi.EndInit();
            //       this.InCourseRunnerStatus.CourceImage.Fill=new ImageBrush(bi);
            //    Canvas.SetTop(this.InCourseRunnerStatus.Circle1, 230);
            //    Canvas.SetLeft(this.InCourseRunnerStatus.Circle1, 290);
            //    Canvas.SetTop(this.InCourseRunnerStatus.Circle2, 220);
            //    Canvas.SetLeft(this.InCourseRunnerStatus.Circle2, 310);
            //         this.InCourseRunnerStatus.MiddleGate.ClearMarksReset();
            //       this.InCourseRunnerStatus.GoalGate.ClearMarksReset();
            //     this.InCourseRunnerStatus.StopAfterGoaled.ClearMarksReset();
            //   this.InCourseRunnerStatus.Circle1.ClearMarksReset();
            //       this.InCourseRunnerStatus.Circle2.ClearMarksReset();
            //     this.InCourseRunnerStatus.ShortCut.ClearMarksReset();

            //            BitmapImage bio = new BitmapImage();
            //            bio.BeginInit();
            //            bio.StreamSource=myAssembly.GetManifestResourceStream(imgPath+"courceOut.jpg");
            //            bio.EndInit();
            //            this.OutCourseRunnerStatus.CourceImage.Fill = new ImageBrush(bio) ;
            //            Canvas.SetTop(this.OutCourseRunnerStatus.GoalGate, Canvas.GetTop(this.OutCourseRunnerStatus.GoalGate)-5);
            //          Canvas.SetTop(this.OutCourseRunnerStatus.StopAfterGoaled, Canvas.GetTop(this.OutCourseRunnerStatus.StopAfterGoaled)-5);
            //        Canvas.SetTop(this.OutCourseRunnerStatus.MiddleGate, Canvas.GetTop(this.OutCourseRunnerStatus.MiddleGate)+10);
            //           this.OutCourseRunnerStatus.MiddleGate.MoveTop(5);
            //         this.OutCourseRunnerStatus.GoalGate.MoveTop(-5);
            //       this.OutCourseRunnerStatus.StopAfterGoaled.MoveTop(-5);
            //     this.OutCourseRunnerStatus.MiddleGate.ClearMarksReset();
            //   this.OutCourseRunnerStatus.GoalGate.ClearMarksReset();
            //        this.OutCourseRunnerStatus.StopAfterGoaled.ClearMarksReset();
            //      this.OutCourseRunnerStatus.ShortCut.ClearMarksReset();
            //    this.OutCourseRunnerStatus.Circle1.ClearMarksReset();
            //  this.OutCourseRunnerStatus.Circle2.ClearMarksReset();

            //   this.InCourseRunner.CourseNameDisplay.Text = @"インコース";
            //   this.OutCourseRunner.CourseNameDisplay.Text = @"アウトコース";
            this.InCourseRunner.CourseNameStatus = @"インコース";
            this.InCourseRunner.BuildFireworksView();

            this.OutCourseRunner.CourseNameStatus = @"アウトコース";
            this.OutCourseRunner.BuildFireworksView();
        }

        public void ResetPresentation()
        {
            InCourseRunner.ResetRunnerTimerCounter();
            InCourseRunner.HiddenRunnerStatus();

//            InCourseRunner.TimeCounter.ResetCounter();
            OutCourseRunner.ResetRunnerTimerCounter();
            OutCourseRunner.HiddenRunnerStatus();
//            OutCourseRunner.TimeCounter.ResetCounter();
            ResetTimerCounter();

            this.InCourseRunner.ShowDriftCourse("", false);

            // 難所特別表示のリセット
  //          InCourseRunnerStatus.DifficultPointStatus.ResetImage();
  //          OutCourseRunnerStatus.DifficultPointStatus.ResetImage();
        }

        public RoundInfo CurrentRoundInfo
        {
            get
            {
                return this.Resources["CurrentRoundInfo"] as RoundInfo;
            }
        }

        public RunnerInfo CurrentInCourseRunnerInfo
        {
            get
            {
                return this.InCourseRunnerStatus.CurrentRunner;
            }
        }

        public RunnerInfo CurrentOutCourseRunnerInfo
        {
            get
            {
                return this.OutCourseRunnerStatus.CurrentRunner;
            }
        }

        public int TimeCountCurrentTime
        {
            get
            {
             //   return this.mainTimeConter.CurrentTime;
                return this.mainTimeConter.GetCurrentTimeCount();
            }
        }

        public void StartTimeCounter()
        {
            this.mainTimeConter.Start();
        }

        public void StopTimeCounter()
        {
            this.mainTimeConter.Stop();
        }

        public void ResetTimerCounter()
        {
            this.mainTimeConter.ResetCounter();
        }

        public UserControlRunnerStatus InCourseRunner
        {
            get
            {
                return this.InCourseRunnerStatus;
            }
        }

        public UserControlRunnerStatus OutCourseRunner
        {
            get
            {
                return this.OutCourseRunnerStatus;
            }
        }

        private void mainTimeConter_Loaded(object sender, RoutedEventArgs e)
        {

        }

        // 2012/9/1 九州大会暫定
        public void ShowDriftTurnCourse(string couseName, bool on)
        {
            this.InCourseRunner.ShowDriftCourse(couseName, on);
        }

    }
}
